import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
import os
from mpl_toolkits.mplot3d import Axes3D  # 导入3D绘图模块

# .csv数据文件目录
directory = "src/build/"

# 读取数据并绘图
i_values = [1, 2, 3]
n_values = [10, 40, 160]


for i in i_values:
    fig = plt.figure(figsize=(10, 8)) # 为每个i创建一个新的图形
    if i==2:
        data = pd.read_csv(f'{directory}data_test_2_n.csv', header=None)
    else:
        data = pd.read_csv(f'{directory}data_test_2.csv', header=None)
    plt.plot(data[0], data[1], 'k--', label='Exact function')
    data = pd.read_csv(f'{directory}data_test_2_p{i}.csv', header=None)  # 指定没有列标题
    plt.plot(data[0], data[1], label=f'n={i}')
    if i==1:
        plt.title(f'test2: PPFormSpline "complete"')
    elif i==2:
        plt.title(f'test2: PPFormSpline "natural"')
    elif i==3:
        plt.title(f'test2: PPFormSpline "periodic"')
    plt.legend(loc='best')
    plt.savefig(f'figure/test_2_p{i}.png')
    plt.close()

for i in i_values:
    fig = plt.figure(figsize=(10, 8)) # 为每个i创建一个新的图形
    if i==2:
        data = pd.read_csv(f'{directory}data_test_2_n.csv', header=None)
    else:
        data = pd.read_csv(f'{directory}data_test_2.csv', header=None)
    plt.plot(data[0], data[1], 'k--', label='Exact function')
    data = pd.read_csv(f'{directory}data_test_2_b{i}.csv', header=None)  # 指定没有列标题
    plt.plot(data[0], data[1], label=f'n={i}')
    if i==1:
        plt.title(f'test2: BSpline "complete"')
    elif i==2:
        plt.title(f'test2: BSpline "natural"')
    elif i==3:
        plt.title(f'test2: BSpline "periodic"')
    plt.legend(loc='best')
    plt.savefig(f'figure/test_2_b{i}.png')
    plt.close()
